<template>
    <div>
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a @tap="getphoto(item.id)" :class="['mui-control-item',item.id==0?'mui-active':'']"  v-for="(item, index) in category" :key="item.id">
                        {{item.title}}
                    </a>
                </div>
            </div>
		</div>
        <!-- 图片展示 -->
        <ul>
            <router-link tag="li" :to="'/home/photoinfo/'+item.id" v-for="item in photolist">
                <img v-lazy="item.img_url">
                <div class="img_con">
                    <div class="con-title">{{item.title}}</div>
                    <div class="con-zhaiyao">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
    import mui from '../../lib/mui/js/mui.min.js'
    import {Toast} from 'mint-ui'
    
    export default {
        data () {
            return {
                category:[],
                photolist:[]
            }
        },
        created() {
            this.getcategory();
            this.getphoto(0);
        },
        mounted() {//Dom全部渲染出来
            //初始化的时机很重要
            mui('.mui-scroll-wrapper').scroll({
	            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            }); 
        },
        methods: {
            getcategory(){
                this.$http.get('api/getimgcategory').then(res=>{
                    console.log(res.body);
                    if(res.body.status==0){
                        res.body.message.unshift({title:"全部",id:0})
                        this.category = res.body.message
                    }else{
                        Toast("请求失败")
                    }
                });
            },
            getphoto(id){
                this.$http.get('api/getimages/'+id).then(res=>{
                    if(res.body.status==0){
                        console.log(res.body);
                        this.photolist = res.body.message
                    }else{
                        Toast("请求失败")
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
*{
    touch-action: pan-y
}

ul{
    list-style: none;
    padding: 0;
    margin: 0;
    padding: 0 10px;
    li{
        margin-bottom: 5px;
        position: relative;
        img{
            width: 100%;
        }
        .img_con{
            background-color: rgba(0,0,0,0.7);
            position: absolute;
            bottom: 0;
            width: 100%;
            color: #fff;
            max-height: 86px;
            padding: 2px 6px;
            .con-title{
                font-size: 16px;
            }
            .con-zhaiyao{
                font-size: 14px;
                color: #ccc;
            }
        }
    }
}

image[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
</style>